package fr.cephb.joperon.core;

import java.util.Calendar;
import java.util.GregorianCalendar;
/**
 * Basic class to handle Mario Foglio's date format :YYYYMMDD_HHMMSS.
 */
public class Ymd
	{
	
	/** returns a Calendar as a Ymd */
	public static String  ymd(Calendar date)
		{
		if(date==null) date= new GregorianCalendar();
		StringBuilder b= new StringBuilder();
		b.append(date.get(Calendar.YEAR));
		int n=1+date.get(Calendar.MONTH);
		b.append(n<10?"0"+n:String.valueOf(n));
		n=date.get(Calendar.DAY_OF_MONTH);
		b.append(n<10?"0"+n:String.valueOf(n));
		b.append("_");
		n=date.get(Calendar.HOUR_OF_DAY);
		b.append(n<10?"0"+n:String.valueOf(n));
		n=date.get(Calendar.MINUTE);
		b.append(n<10?"0"+n:String.valueOf(n));
		n=date.get(Calendar.SECOND);
		b.append(n<10?"0"+n:String.valueOf(n));
		return b.toString();
		}
	
	/** return the Ymd now */
	public static String now()
		{
		return ymd(new GregorianCalendar());
		}

}
